 
import { ABaseDecision } from "GameLoop/DecisionMaking/BaseDecision";
import { MainStrategy } from "GameLoop/WorldState/EntityManager/CreateStrategy/MainStrategy";
import { OutMineStrategy } from "GameLoop/WorldState/EntityManager/CreateStrategy/OutMineStrategy";
import { Roles } from "utils/creep/setups";
import { PositionHelper } from "utils/position/PositionHelper";

/**
 * 新增外矿房间
 */
export class AddMineRoomDecision< T extends "AddRoomEvent"="AddRoomEvent"> extends ABaseDecision<T>
{
   
    public isExpired(event: AddRoomEvent, region: string): boolean 
    {
        return true;
    }
    public makeTask(event: AddRoomEvent, region: string): IDecisionCode<T>|false
    {
        if(event.type == 3)
        {
            global.Log.Info(`更新外矿房间 : ${event.region}`);
            
            const lordroom = Game.rooms[event.region] ;
            if(lordroom && lordroom.memory.stats)
            {
                const seqid = PositionHelper.seqId(event.room);
                {
                    Game.rooms[event.room].memory={
                        config:{type:3},
                        lord: lordroom.name,
                        seqId:seqid,
                    } as any;
                    if(OutMineStrategy.check(Game.rooms[event.room],this.WorldGetter.EntityDB))
                    {
                        this.WorldGetter.registerNotify(Game.shard.name,{type:"AddMineRoom",region:event.region,room:event.room})
                    }
                    else 
                    {
                        Game.rooms[event.room].memory={ } as any;
                    }
                    
                    return false;
                }
 
            }
        }
        return false;
        // return code
    }
    
}